<html lang="en"><head>
    <meta charset="UTF-8">
    <title>添加分类</title>
    <script src="${request.contextPath}/plug/vue/dist/vue.min.js"></script>
    <link href="${request.contextPath}/plug/iview/dist/styles/iview.css" rel="stylesheet">
    <script src="${request.contextPath}/plug/iview/dist/iview.min.js"></script>
    <script src="${request.contextPath}/plug/jquery/jquery.min.js"></script>
    <script src="${request.contextPath}/plug/form-create/province_city.js"></script>
    <script src="${request.contextPath}/plug/form-create/province_city_area.js"></script>
    <script src="${request.contextPath}/plug/form-create/form-create.min.js"></script><style type="text/css">
    .fc-upload-btn, .fc-files {
    display: inline-block;
    width: 58px;
    height: 58px;
    text-align: center;
    line-height: 58px;
    border: 1px solid #c0ccda;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, .1);
    margin-right: 4px;
    box-sizing: border-box;
}

.__fc_h {
    display: none;
}

.__fc_v {
    visibility: hidden;
}

.fc-files img {
    width: 100%;
    height: 100%;
    display: inline-block;
    vertical-align: top;
}

.fc-upload-btn {
    border: 1px dashed #c0ccda;
    cursor: pointer;
}

.fc-upload .fc-upload-cover {
    opacity: 0;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, .6);
    transition: opacity .3s;
}

.fc-upload .fc-upload-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
}

.fc-files:hover .fc-upload-cover {
    opacity: 1;
}

.fc-hide-btn .ivu-upload .ivu-upload {
    display: none;
}

.fc-upload .ivu-upload-list {
    margin-top: 0;
}</style>
    <style>
        /*弹框样式修改*/
        .ivu-modal{top: 20px;}
        .ivu-modal .ivu-modal-body{padding: 10px;}
        .ivu-modal .ivu-modal-body .ivu-modal-confirm-head{padding:0 0 10px 0;}
        .ivu-modal .ivu-modal-body .ivu-modal-confirm-footer{display: none;padding-bottom: 10px;}
        .ivu-date-picker {display: inline-block;line-height: normal;width: 280px;}
        .ivu-modal-footer{display: none;}
        body{padding: 20px;}
    </style>
</head>
<body>
<input type="hidden" id="rowKey" value="${id!}">
<script>
    window.$f = null
    formCreate.formSuccess = function(form,$r){
        parent.SuccessCateg();
parent.layer.close(parent.layer.getFrameIndex(window.name));        //刷新父级页面
//        parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
        //关闭当前窗口
//        var index = parent.layer.getFrameIndex(window.name);
//        parent.layer.close(index);
        //提交成功后按钮恢复
        console.log($r);
        // $r.loading(false);
    };

    (function () {
        var create = (function () {
            var getRule = function () {
                var rule = [{"type":"input","field":"name","title":"分类名称","value":"","props":{"type":"text","placeholder":"请输入分类名称"},"validate":[],"col":[]}];
                 var data = '<#if name??>${name}</#if>';
                if(""!=data){
                    rule[0].value=data;
                }
                rule.forEach(function (c) {
                    if ((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]') {
                        if (c.props.data.indexOf('js.') === 0) {
                            c.props.data = window[c.props.data.replace('js.', '')];
                        }
                    }
                });
                return rule;
            }, vm = new Vue,name = 'formBuilderExec';
            var _b = false;
            window[name] =  function create(el, callback) {
                if(_b) return ;
                _b = true;
                if (!el) el = document.body;
                $f = formCreate.create(getRule(), {
                    el: el,
                    form:{"inline":false,"labelPosition":"right","labelWidth":125,"showMessage":true,"autocomplete":"off"},
                    row:[],
                    submitBtn:{},
                    resetBtn:{},
                    iframeHelper:true,
                    global:{
                        upload: {
                            props:{
                                onExceededSize: function (file) {
                                    vm.$Message.error(file.name + '超出指定大小限制');
                                },
                                onFormatError: function () {
                                    vm.$Message.error(file.name + '格式验证失败');
                                },
                                onError: function (error) {
                                    vm.$Message.error(file.name + '上传失败,(' + error + ')');
                                },
                                onSuccess: function (res, file) {
                                    if (res.code == 200) {
                                        file.url = res.data.filePath;
                                    } else {
                                        vm.$Message.error(res.msg);
                                    }
                                },
                            },
                        },
                    },
                    //表单提交事件
                    onSubmit: function (formData) {
                        $f.btn.loading(true);
                        var url = '${request.contextPath}/admin/file/addType';
                         var rowKey = $("#rowKey").val();
                        if(""!= rowKey){
                            formData.id = rowKey;
                            url = url = '${request.contextPath}/admin/file/updateType';
                        }
                        $.ajax({
                            url: url,
                            type: 'POST',
                            dataType: 'json',
                            data: formData,
                            success: function (res) {
                                if (res.code == 200) {
                                    vm.$Message.success(res.msg);
                                    $f.btn.loading(false);
                                    formCreate.formSuccess && formCreate.formSuccess(res, $f, formData);
                                    callback && callback(0, res, $f, formData);
                                    //TODO 表单提交成功!
                                } else {
                                    vm.$Message.error(res.msg || '表单提交失败');
                                    $f.btn.loading(false);
                                    callback && callback(1, res, $f, formData);
                                    //TODO 表单提交失败
                                }
                            },
                            error: function () {
                                vm.$Message.error('表单提交失败');
                                $f.btn.loading(false);
                            }
                        });
                    }
                });
                return $f;
            };
            return window[name];
        }());

        window.$f = create();
//        create();
    })();
</script>
</body></html>